class Stack:
    def __init__(self):
        self.stack = []  # 创建一个空列表作为栈

    def is_empty(self):
        return not bool(self.stack)  # 判断栈是否为空

    def push(self, item):
        self.stack.append(item)  # 入栈，将元素添加到栈顶

    def pop(self):
        if self.is_empty():
            return "栈已空"
        else:
            return self.stack.pop()  # 出栈，将栈顶元素删除并返回

    def peek(self):
        if self.is_empty():
            return "此时，栈为空"
        else:
            return self.stack[-1]  # 返回栈顶元素

    def size(self):
        return len(self.stack)  # 返回栈的大小


# 演示程序
stack = Stack()

while True:
    print("----------------------")
    print("1. 入栈")
    print("2. 出栈")
    print("3. 查看栈顶元素")
    print("4. 查看栈大小")
    print("5. 判断栈是否为空")
    print("0. 退出程序")

    choice = input("请选择操作: ")

    if choice == "1":
        item = input("请输入要入栈的元素: ")
        stack.push(item)
        print("元素", item, "已入栈")
    elif choice == "2":
        item = stack.pop()
        print("元素", item, "已出栈")
    elif choice == "3":
        item = stack.peek()

        print("栈顶元素为:", item)
    elif choice == "4":
        size = stack.size()
        print("栈大小为:", size)
    elif choice == "5":
        is_empty = stack.is_empty()
        print("栈是否为空:", is_empty)
    elif choice == "0":
        break
    else:
        print("无效的操作，请重新选择")